<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>播放</title>
    <link rel="stylesheet" href="/index/dplayer/DPlayer.min.css">
    <script type="text/javascript" src="/index/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="/index/dplayer/DPlayer.min.js"></script>

</head>
<body>
    <div id="dplayer" ></div>
</body>

<script type="text/javascript">
    $(function () {

        // var video = document.getElementById('my-video');
        //
        const dp = new DPlayer({
            container: document.getElementById('dplayer'),
            preload: 'auto',
            autoplay: true,
            video: {
                url: '{$img_path}{$section.url}',
                pic: '/index/assets/load.gif'
            },
        });

        if('{$play_time}'){
            dp.seek(parseInt('{$play_time}'));
        }

        dp.on('canplay',function(){
            window.parent.$('iframe').height(document.documentElement.scrollHeight || document.body.scrollHeight);
        })

        dp.on('timeupdate', function() {
            //用秒数来显示当前播放进度
            playTime = Math.floor(dp.video.currentTime);

            if('{$try_see}' > 0 && playTime>='{$try_see}'){
                // video.stop();
                // exitFullscreen();
                window.parent.$('.vip').show();

                window.parent.$('iframe').remove();
            }

            if(playTime%10==0 ){
                playRecord(playTime,parseInt(dp.video.duration));
            }
        });
    })

    var flag = -1;

    //观看记录
    function playRecord(playTime,allTime){

        if(flag!=playTime){

            $.post('{:url("playRecord")}',{movie_id:'{$movie.id}',section_id:'{$section.id}',play_time:playTime,all_time:allTime},function(res){
                // flag = 0;
                flag=playTime;

            })
        }
    }

	// ele:全屏的对象
	function requestFullscreen(ele) {
		// 全屏兼容代码
		if (ele.requestFullscreen) {
			ele.requestFullscreen();
		} else if (ele.webkitRequestFullscreen) {
			ele.webkitRequestFullscreen();
		} else if (ele.mozRequestFullScreen) {
			ele.mozRequestFullScreen();
		} else if (ele.msRequestFullscreen) {
			ele.msRequestFullscreen();
		}
	}

    // 取消全屏
    function exitFullscreen() {
        if (document.exitFullscreen) {
            document.exitFullscreen();
        } else if (document.webkitExitFullscreen) {
            document.webkitExitFullscreen();
        } else if (document.msExitFullscreen) {
            document.msExitFullscreen();
        } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        }
    }

</script>
</html>